package com.cssw.fyzb.busi.api.user;


import com.cssw.fyzb.busi.service.user.UserService;
import com.cssw.fyzb.core.dao.user.DistrictDao;
import com.cssw.fyzb.core.model.dodb.District;
import com.cssw.fyzb.core.model.dodb.User;
import com.cssw.fyzb.core.model.vo.user.UserIdVo;
import com.cssw.fyzb.core.model.vo.user.UserInfoVo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * 获取用户信息
 *
 * @author YangYiQun
 */
@Function(description = "检查用户手机号是否存在用户", parameters = {
        @Parameter(name = "mobile", type = Type.String, description = "手机号码", required = true)
})
@Component
public class CheckMobile implements Action {

    @Autowired
    private UserService userService;

    private static final Logger logger = LoggerFactory.getLogger(CheckMobile.class);

    @Override
    public Response execute(Request request) throws Exception {
        String mobile = request.getString("mobile");
        try {
            User user = userService.getByMobile(mobile);
            UserIdVo userIdVo = new UserIdVo();
            if (null != user) {
                userIdVo.setUserId(user.getUserId());
            }
            return Response.success().put("data", userIdVo);
        } catch (Exception e) {
            logger.error("", e);
            return Response.fail("用户信息获取失败");
        }
    }
}
